package com.csjbot.alicemobilecontrol;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;

import com.alibaba.fastjson.JSON;
import com.csjbot.alicemobilecontrol.Entity.CtrlCmd;
import com.csjbot.alicemobilecontrol.Events.ServerEvent;
import com.csjbot.alicemobilecontrol.Listener.ControlListener;
import com.csjbot.alicemobilecontrol.client.NettyClientNew;
import com.csjbot.alicemobilecontrol.client.nettyHandler.ClientListener;
import com.csjbot.alicemobilecontrol.tool.CSJToast;
import com.csjbot.alicemobilecontrol.tool.Contant;
import com.csjbot.alicemobilecontrol.tool.SharedPreferencesUtils;
import com.orhanobut.logger.Logger;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import static com.csjbot.alicemobilecontrol.R.id.et_con;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, View.OnLongClickListener, ClientListener {
    public static final int TOP = 0;
    public static final int BOTTOM = 1;
    public static final int LEFT = 2;
    public static final int RIGHT = 3;
    private Button mSend, arrow_top, arrow_left, arrow_bottom, btnLogin,
            arrow_right, btn_smile, btn_cry, btn_wave_left, btn_wave_right;

    private Button btn_point_1, btn_point_2, btn_point_3, btn_point_4, btn_point_5;
    private EditText mEditText, editText_ipaddr;
    private boolean isSend;
    private MainActivity mContext;
    private String[] contantItem = new String[]{Contant.BTN_1, Contant.BTN_2, Contant.BTN_3, Contant.BTN_4, Contant.BTN_5,
            Contant.BTN_6, Contant.BTN_7, Contant.BTN_8, Contant.BTN_9, Contant.BTN_10, Contant.BTN_11, Contant.BTN_12,
            Contant.BTN_13, Contant.BTN_14, Contant.BTN_15,
            Contant.BTN_16, Contant.BTN_17, Contant.BTN_18, Contant.BTN_19, Contant.BTN_20, Contant.BTN_21};
    private int[] buttonId = new int[]{R.id.btn_1, R.id.btn_2, R.id.btn_3, R.id.btn_4, R.id.btn_5, R.id.btn_6,
            R.id.btn_7, R.id.btn_8, R.id.btn_9, R.id.btn_10, R.id.btn_11, R.id.btn_12, R.id.btn_13,
            R.id.btn_14, R.id.btn_15, R.id.btn_16, R.id.btn_17, R.id.btn_18, R.id.btn_19, R.id.btn_20, R.id.btn_21};
    private List<Button> buttonList = new ArrayList<>();
    private String mCmd;
    private boolean isStop;
    private boolean isLongClick;

    private boolean isConnected;

    private ControlListener mControlSendListener;
    NettyClientNew clientNew = NettyClientNew.getInstence();
    private EventBus eventBus;

    private Handler mMhandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case TOP:
                    if (!isStop) {
                        arrow_top.performClick();
                    }
                    mMhandler.sendEmptyMessageDelayed(TOP, 700);
                    break;
                case BOTTOM:
                    if (!isStop) {
                        arrow_bottom.performClick();
                    }
                    mMhandler.sendEmptyMessageDelayed(BOTTOM, 700);
                    break;
                case LEFT:
                    if (!isStop) {
                        arrow_left.performClick();
                    }
                    mMhandler.sendEmptyMessageDelayed(LEFT, 700);
                    break;
                case RIGHT:
                    if (!isStop) {
                        arrow_right.performClick();
                    }
                    mMhandler.sendEmptyMessageDelayed(RIGHT, 700);
                    break;
            }

        }
    };

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        StatService.start(this);
//        StatService.setAppKey("263a168e44");
//        String testDeviceId = StatService.getTestDeviceId(this);
//        android.util.Log.d("BaiduMobStat", "Test DeviceId : " + testDeviceId);
//        StatService.setDebugOn(true);


        mContext = this;
        initView();
        initButtonText();
        initLongPress();
        initLongClickListener();

        if (eventBus == null) {
            eventBus = EventBus.getDefault();
        }
        eventBus.register(this);
    }

    @Override
    protected void onDestroy() {
        if (eventBus != null) {
            eventBus.unregister(this);
        }
        super.onDestroy();
    }

    private void initButtonText() {

        for (int i = 0; i < contantItem.length; i++) {
            String cmd = (String) SharedPreferencesUtils.getParam(mContext, contantItem[i], "");
            if (!TextUtils.isEmpty(cmd)) {
                buttonList.get(i).setText(cmd);
            }
        }

        String txt = (String) SharedPreferencesUtils.getParam(this, Contant.BTN_POINT_1, "");
        if (!TextUtils.isEmpty(txt)) {
            btn_point_1.setText("*");
        }

        txt = (String) SharedPreferencesUtils.getParam(this, Contant.BTN_POINT_2, "");
        if (!TextUtils.isEmpty(txt)) {
            btn_point_2.setText("*");
        }

        txt = (String) SharedPreferencesUtils.getParam(this, Contant.BTN_POINT_3, "");
        if (!TextUtils.isEmpty(txt)) {
            btn_point_3.setText("*");
        }

        txt = (String) SharedPreferencesUtils.getParam(this, Contant.BTN_POINT_4, "");
        if (!TextUtils.isEmpty(txt)) {
            btn_point_4.setText("*");
        }

        txt = (String) SharedPreferencesUtils.getParam(this, Contant.BTN_POINT_5, "");
        if (!TextUtils.isEmpty(txt)) {
            btn_point_5.setText("*");
        }
    }


    private void initLongClickListener() {
        for (Button button : buttonList) {
            button.setOnLongClickListener(this);
        }

    }

    private void initLongPress() {
        // TODO: 2017-09-21 上连击
        arrow_top.setOnTouchListener(new View.OnTouchListener() {
            private long mDown_time;

            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        mDown_time = System.currentTimeMillis();
                        isLongClick = false;
                        isStop = false;
                        mMhandler.sendEmptyMessageDelayed(TOP, 700);
                        break;
                    case MotionEvent.ACTION_UP:
                        if (System.currentTimeMillis() - mDown_time > 300) {
                            isLongClick = true;
                        }
                        isStop = true;
                        mMhandler.removeMessages(TOP);
                        break;
                }
                return false;
            }
        });
        // TODO: 2017-09-21 左连击
        arrow_left.setOnTouchListener(new View.OnTouchListener() {
            private long mDown_time;

            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        mDown_time = System.currentTimeMillis();
                        isLongClick = false;
                        isStop = false;
                        mMhandler.sendEmptyMessageDelayed(LEFT, 700);
                        break;
                    case MotionEvent.ACTION_UP:
                        if (System.currentTimeMillis() - mDown_time > 300) {
                            isLongClick = true;
                        }
                        isStop = true;
                        mMhandler.removeMessages(LEFT);
                        break;
                }
                return false;
            }
        });
        // TODO: 2017-09-21 下连击
        arrow_bottom.setOnTouchListener(new View.OnTouchListener() {
            private long mDown_time;

            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        mDown_time = System.currentTimeMillis();
                        isLongClick = false;
                        isStop = false;
                        mMhandler.sendEmptyMessageDelayed(BOTTOM, 700);
                        break;
                    case MotionEvent.ACTION_UP:
                        if (System.currentTimeMillis() - mDown_time > 300) {
                            isLongClick = true;
                        }
                        isStop = true;
                        mMhandler.removeMessages(BOTTOM);
                        break;
                }
                return false;
            }
        });
        // TODO: 2017-09-21 右连击
        arrow_right.setOnTouchListener(new View.OnTouchListener() {
            private long mDown_time;

            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        mDown_time = System.currentTimeMillis();
                        isLongClick = false;
                        isStop = false;
                        mMhandler.sendEmptyMessageDelayed(RIGHT, 700);
                        break;
                    case MotionEvent.ACTION_UP:
                        if (System.currentTimeMillis() - mDown_time > 300) {
                            isLongClick = true;
                        }
                        isStop = true;
                        mMhandler.removeMessages(RIGHT);
                        break;
                }
                return false;
            }
        });

    }

    private void initView() {
        mEditText = (EditText) findViewById(et_con);
        mSend = (Button) findViewById(R.id.btn_send);

        btnLogin = (Button) findViewById(R.id.buttonLogin);

        for (int id : buttonId) {
            buttonList.add((Button) findViewById(id));
        }
        arrow_top = (Button) findViewById(R.id.arrow_top);
        arrow_left = (Button) findViewById(R.id.arrow_left);
        arrow_bottom = (Button) findViewById(R.id.arrow_bottom);
        arrow_right = (Button) findViewById(R.id.arrow_right);
        btn_smile = (Button) findViewById(R.id.btn_smile);
        btn_cry = (Button) findViewById(R.id.btn_cry);
        btn_wave_left = (Button) findViewById(R.id.btn_wave_left);
        btn_wave_right = (Button) findViewById(R.id.btn_wave_right);

        editText_ipaddr = (EditText) findViewById(R.id.editText_ipaddr);
        this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        editText_ipaddr.setInputType(EditorInfo.TYPE_CLASS_PHONE);
        editText_ipaddr.setSelection(editText_ipaddr.getText().toString().length());

        mSend.setOnClickListener(this);
        btnLogin.setOnClickListener(this);
        btnLogin.setOnLongClickListener(this);

        for (Button button : buttonList) {
            button.setOnClickListener(this);
        }

        btn_point_1 = (Button) findViewById(R.id.btn_point_1);
        btn_point_2 = (Button) findViewById(R.id.btn_point_2);
        btn_point_3 = (Button) findViewById(R.id.btn_point_3);
        btn_point_4 = (Button) findViewById(R.id.btn_point_4);
        btn_point_5 = (Button) findViewById(R.id.btn_point_5);

        btn_point_1.setOnLongClickListener(this);
        btn_point_2.setOnLongClickListener(this);
        btn_point_3.setOnLongClickListener(this);
        btn_point_4.setOnLongClickListener(this);
        btn_point_5.setOnLongClickListener(this);

        arrow_top.setOnClickListener(this);
        arrow_left.setOnClickListener(this);
        arrow_bottom.setOnClickListener(this);
        arrow_right.setOnClickListener(this);
        btn_smile.setOnClickListener(this);
        btn_cry.setOnClickListener(this);
        btn_wave_left.setOnClickListener(this);
        btn_wave_right.setOnClickListener(this);
    }

    private void sendMessageString(String jsonString) {
        clientNew.sendMessage(jsonString);
    }

    private void sendMessage(CtrlCmd cmd) {
        String jsonString = JSON.toJSONString(cmd);
        clientNew.sendMessage(jsonString);
    }

    private CtrlCmd cmd;
    private String cmdString;

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.buttonLogin:
                if (!isConnected) {
                    clientNew.connect(editText_ipaddr.getText().toString(), this);
                    Logger.d("connect");
                } else {
                    CSJToast.showToast(this, "长按断开连接");
                }
                break;
            case R.id.btn_send:
                isSend = true;
                String control = mEditText.getText().toString().trim();
                if (TextUtils.isEmpty(control)) {
                    CSJToast.showToast(mContext, "命令不能为空，请重新输入");
                    break;
                }
                CSJToast.showToast(mContext, "命令已发送");
//                mEditText.setText("");
                // TODO: 2017-09-21  处理逻辑
                if (mControlSendListener != null) {
                    mControlSendListener.sendCmd(control);
                }

//                CtrlCmd cmd = new CtrlCmd(0, control);
//                sendMessage(cmd);
                cmdString = String.format(Locale.getDefault(), "{\"msg_id\":\"USER_SPEECH\",\"content\":\"%s\"}"
                        , mEditText.getText().toString());
                sendMessageString(cmdString);
                break;
            case R.id.btn_1:
                mEditText.setText(buttonList.get(0).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            case R.id.btn_2:
                mEditText.setText(buttonList.get(1).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            case R.id.btn_3:
                mEditText.setText(buttonList.get(2).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            case R.id.btn_4:
                mEditText.setText(buttonList.get(3).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            case R.id.btn_5:
                mEditText.setText(buttonList.get(4).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            case R.id.btn_6:
                mEditText.setText(buttonList.get(5).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            case R.id.btn_7:
                mEditText.setText(buttonList.get(6).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            case R.id.btn_8:
                mEditText.setText(buttonList.get(7).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            case R.id.btn_9:
                mEditText.setText(buttonList.get(8).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            case R.id.btn_10:
                mEditText.setText(buttonList.get(9).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            case R.id.btn_11:
                mEditText.setText(buttonList.get(10).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            case R.id.btn_12:
                mEditText.setText(buttonList.get(11).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            case R.id.btn_13:
                mEditText.setText(buttonList.get(12).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            case R.id.btn_14:
                mEditText.setText(buttonList.get(13).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            case R.id.btn_15:
                mEditText.setText(buttonList.get(14).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;

            case R.id.btn_16:
                mEditText.setText(buttonList.get(15).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;

            case R.id.btn_17:
                mEditText.setText(buttonList.get(16).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;

            case R.id.btn_18:
                mEditText.setText(buttonList.get(17).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;

            case R.id.btn_19:
                mEditText.setText(buttonList.get(18).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;

            case R.id.btn_20:
                mEditText.setText(buttonList.get(19).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;

            case R.id.btn_21:
                mEditText.setText(buttonList.get(20).getText().toString().trim());
                mEditText.setSelection(mEditText.getText().toString().length());
                break;
            // TODO: 2017-09-21 上下左右
            case R.id.arrow_top:
                if (!isLongClick) {
                    sendMessageString(Contant.GO_FORWORD);
                }
                break;
            case R.id.arrow_left:
                if (!isLongClick) {
                    sendMessageString(Contant.TURN_LEFT);
                }
                break;
            case R.id.arrow_bottom:
                if (!isLongClick) {
                    sendMessageString(Contant.GO_BACK);
                }
                break;
            case R.id.arrow_right:
                if (!isLongClick) {
                    sendMessageString(Contant.TURN_RIGHT);
                }
                break;
            // TODO: 2017-09-21 哭笑挥左挥右
            case R.id.btn_smile:
                sendMessageString(Contant.SMILE);
                break;
            case R.id.btn_cry:
                sendMessageString(Contant.CRY);
                break;
            case R.id.btn_wave_left:
                if (mControlSendListener != null) {
                    mControlSendListener.waveLeft();
                }
                break;
            case R.id.btn_wave_right:
                if (mControlSendListener != null) {
                    mControlSendListener.waveRight();
                }
                break;
            default:
                break;
        }
        if (!TextUtils.isEmpty(mCmd) && !isSend) {
            mEditText.setText(mCmd);
            mEditText.setSelection(mEditText.getText().toString().length());
        }
        isSend = false;
    }

    String point_key;

    @Override
    public boolean onLongClick(View view) {
        switch (view.getId()) {
            case R.id.buttonLogin:
                if (isConnected) {
                    clientNew.disconnect();
                    Logger.d("disconnect");
                }
                return true;
            case R.id.btn_point_1:
                point_key = Contant.BTN_POINT_1;
                sendMessageString(Contant.GET_POINT);
                return true;
            case R.id.btn_point_2:
                point_key = Contant.BTN_POINT_2;
                sendMessageString(Contant.GET_POINT);
                return true;
            case R.id.btn_point_3:
                point_key = Contant.BTN_POINT_3;
                sendMessageString(Contant.GET_POINT);
                return true;
            case R.id.btn_point_4:
                point_key = Contant.BTN_POINT_4;
                sendMessageString(Contant.GET_POINT);
                return true;
            case R.id.btn_point_5:
                point_key = Contant.BTN_POINT_5;
                sendMessageString(Contant.GET_POINT);
                return true;
        }
        Editable control = mEditText.getText();
        String cmd = String.valueOf(control);
        if (TextUtils.isEmpty(cmd)) {
            CSJToast.showToast(MainActivity.this, "命令不能为空，请重新输入");
            return true;
        }
        switch (view.getId()) {
            case R.id.btn_1:
                SharedPreferencesUtils.setParam(mContext, contantItem[0], cmd);
                buttonList.get(0).setText(cmd);
                break;
            case R.id.btn_2:
                SharedPreferencesUtils.setParam(mContext, contantItem[1], cmd);
                buttonList.get(1).setText(cmd);
                break;
            case R.id.btn_3:
                SharedPreferencesUtils.setParam(mContext, contantItem[2], cmd);
                buttonList.get(2).setText(cmd);
                break;
            case R.id.btn_4:
                SharedPreferencesUtils.setParam(mContext, contantItem[3], cmd);
                buttonList.get(3).setText(cmd);
                break;
            case R.id.btn_5:
                SharedPreferencesUtils.setParam(mContext, contantItem[4], cmd);
                buttonList.get(4).setText(cmd);
                break;
            case R.id.btn_6:
                SharedPreferencesUtils.setParam(mContext, contantItem[5], cmd);
                buttonList.get(5).setText(cmd);
                break;
            case R.id.btn_7:
                SharedPreferencesUtils.setParam(mContext, contantItem[6], cmd);
                buttonList.get(6).setText(cmd);
                break;
            case R.id.btn_8:
                SharedPreferencesUtils.setParam(mContext, contantItem[7], cmd);
                buttonList.get(7).setText(cmd);
                break;
            case R.id.btn_9:
                SharedPreferencesUtils.setParam(mContext, contantItem[8], cmd);
                buttonList.get(8).setText(cmd);
                break;
            case R.id.btn_10:
                SharedPreferencesUtils.setParam(mContext, contantItem[9], cmd);
                buttonList.get(9).setText(cmd);
                break;
            case R.id.btn_11:
                SharedPreferencesUtils.setParam(mContext, contantItem[10], cmd);
                buttonList.get(10).setText(cmd);
                break;
            case R.id.btn_12:
                SharedPreferencesUtils.setParam(mContext, contantItem[11], cmd);
                buttonList.get(11).setText(cmd);
                break;
            case R.id.btn_13:
                SharedPreferencesUtils.setParam(mContext, contantItem[12], cmd);
                buttonList.get(12).setText(cmd);
                break;
            case R.id.btn_14:
                SharedPreferencesUtils.setParam(mContext, contantItem[13], cmd);
                buttonList.get(13).setText(cmd);
                break;
            case R.id.btn_15:
                SharedPreferencesUtils.setParam(mContext, contantItem[14], cmd);
                buttonList.get(14).setText(cmd);
                break;

            case R.id.btn_16:
                SharedPreferencesUtils.setParam(mContext, contantItem[15], cmd);
                buttonList.get(15).setText(cmd);
                break;

            case R.id.btn_17:
                SharedPreferencesUtils.setParam(mContext, contantItem[16], cmd);
                buttonList.get(16).setText(cmd);
                break;

            case R.id.btn_18:
                SharedPreferencesUtils.setParam(mContext, contantItem[17], cmd);
                buttonList.get(17).setText(cmd);
                break;

            case R.id.btn_19:
                SharedPreferencesUtils.setParam(mContext, contantItem[18], cmd);
                buttonList.get(18).setText(cmd);
                break;
            case R.id.btn_20:
                SharedPreferencesUtils.setParam(mContext, contantItem[19], cmd);
                buttonList.get(19).setText(cmd);
                break;

            case R.id.btn_21:
                SharedPreferencesUtils.setParam(mContext, contantItem[20], cmd);
                buttonList.get(20).setText(cmd);
                break;

            default:
                break;
        }
        CSJToast.showToast(MainActivity.this, "已保存命令");
        return true;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void serverStateChanged(ServerEvent event) {
        if (event.getTag() == ServerEvent.CLIENT_CONNECTED) {
        }
        if (event.getTag() == ServerEvent.CLIENT_DISCONNECTED) {
        }
    }

    @Override
    public void recMessage(String msg) {
        Logger.d(msg);
        if (msg.contains("NAVI_GET_CURPOS_RSP")) {
            /**
             * {
             "msg_id":"NAVI_GET_CURPOS_RSP",
             "x":"0",
             "y":"0",
             "z":"0",
             "rotation":"0",
             "error_code":0
             }

             */
            if (point_key != null && point_key.length() > 0) {
                try {
                    JSONObject root = new JSONObject(msg);
                    String navi = String.format(Locale.getDefault(), Contant.NAVI_TO,
                            Float.parseFloat(root.getString("x")),
                            Float.parseFloat(root.getString("y")),
                            Float.parseFloat(root.getString("rotation")));

                    SharedPreferencesUtils.setParam(mContext, point_key, navi);
                    point_key = "";

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    @Override
    public void clientConnected() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                btnLogin.setText("已登录");
                isConnected = true;
                editText_ipaddr.setEnabled(false);
                mEditText.setFocusable(true);
                mEditText.requestFocus();
                CSJToast.showToast(MainActivity.this, "登录成功");
            }
        });
    }

    @Override
    public void clientDisConnected() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                editText_ipaddr.setEnabled(true);
                isConnected = false;
                btnLogin.setText("登录");
                editText_ipaddr.setFocusable(true);
                editText_ipaddr.requestFocus();
                CSJToast.showToast(MainActivity.this, "断开连接");
            }
        });
    }

    public void PointClick(View view) {
        String txt = "";
        switch (view.getId()) {
            case R.id.btn_point_1:
                txt = (String) SharedPreferencesUtils.getParam(this, Contant.BTN_POINT_1, "");
                break;
            case R.id.btn_point_2:
                txt = (String) SharedPreferencesUtils.getParam(this, Contant.BTN_POINT_2, "");
                break;
            case R.id.btn_point_3:
                txt = (String) SharedPreferencesUtils.getParam(this, Contant.BTN_POINT_3, "");
                break;
            case R.id.btn_point_4:
                txt = (String) SharedPreferencesUtils.getParam(this, Contant.BTN_POINT_4, "");
                break;
            case R.id.btn_point_5:
                txt = (String) SharedPreferencesUtils.getParam(this, Contant.BTN_POINT_5, "");
                break;
        }

        if (!TextUtils.isEmpty(txt)) {
            clientNew.sendMessage(txt);
        }
    }

    public void startDance(View view) {
        clientNew.sendMessage("{\"msg_id\":\"USER_DANCE_START\"}");
        CSJToast.showToast(this, "开始跳舞");
    }

    public void BodyAction(View view) {
        switch (view.getId()) {
            case R.id.upLeftHand:
                clientNew.sendMessage(Contant.upLeftHand);
                break;
            case R.id.downLeftHand:
                clientNew.sendMessage(Contant.downLeftHand);
                break;
            case R.id.upRightHand:
                clientNew.sendMessage(Contant.upRightHand);
                break;
            case R.id.downRightHand:
                clientNew.sendMessage(Contant.downRightHand);
                break;
            case R.id.headYes:
                clientNew.sendMessage(Contant.diantou);
                break;
            case R.id.headNo:
                clientNew.sendMessage(Contant.yaotou);
                break;
        }
    }
}
